<?php
//    require_once($_SERVER['DOCUMENT_ROOT'] . '/auth/auth.php');
	require_once('auth/auth.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Welcome!</title>


	<?php
		include('head.php');
	?>

<script type="text/javascript">

// <![CDATA[

function chkExpname() {
    
    form = document.elauncher;
    
    var input = document.getElementById("expnamechk");
    
	if (input) input.className=(validateTextfield(form.expname,false,false))?'validinput':'notvalidinput';
    
	enableSubmit();
}

function chkFilename() {
    
    form = document.elauncher;
	
	var input = document.getElementById("filenamechk");
    
    if (input) input.className=(validateTextfield(form.filename,false,false))?'validinput':'notvalidinput';
    
	enableSubmit();
}

function enableSubmit(){


    form = document.elauncher;
    
    if( (validateTextfield(form.expname, false, false))
        ) {
        document.getElementById("doLaunch").disabled = false;
        document.getElementById("doLaunch").style.color = "#030303";
    } else {
        document.getElementById("doLaunch").disabled = true;
        document.getElementById("doLaunch").style.color = "#7A7A7A";
    }
}

function validateTextfield(fld,warn,spaces) {
    var error = "";
    
    if(spaces) {
        var validChars = /^[a-zA-Z0-9\-\_\s]{2,}$/;
    } else {
        var validChars = /^[a-zA-Z0-9\-\_]{2,}$/;
    }

    if (fld.value == "") {
        if(warn) fld.style.background = '#FFCC66'; 
        error = "Empty field!.\n";
    } else if ((fld.value.length < 4) || (fld.value.length > 20)) { 
        if(warn) fld.style.background = '#FFCC66'; 
        error = "Wrong size!.\n";
    } else if (!validChars.test(fld.value)) {
        if(warn) fld.style.background = '#FFCC66'; 
        error = "mmm.. are you trying something?.\n";
    } else {
        if(warn) fld.style.background = '#bdeaff';
        return true;
    } 
    return false;
}


// ]]>
</script>
</head>


<body>
	<?php 
		$header_title = 'Welcome ' . $_SESSION['SESS_USER_FNAME'] . ' ' . $_SESSION['SESS_USER_LNAME'] . '!';
		include('header.php'); 
		include('menubar.php');
	?>

	<?php 
		if(!isset($_SESSION['LAUNCH_EXPNAME'])) $_SESSION['LAUNCH_EXPNAME']="";
	?>

	<form id="elauncher" name="elauncher" class="elauncher" method="post" action="launch-exec.php" enctype="multipart/form-data" >

      <label>Experiment name</label>
      <input name="expname" type="text" class="textfield" id="expname" maxlength="16" value="<?php echo $_SESSION['LAUNCH_EXPNAME'] ?>" onkeyup="chkExpname()" style="margin-bottom: 20px;"/><div id="expnamechk" class="hidden"></div>

      <label>Settings</label>

	  <input name="bexpident" type="checkbox" class="checkbox" id="bexpident" value=1 /><label>Identify numbers?</label>

      <input name="bexpfactor" type="checkbox" class="checkbox" id="bexpfacor" value=1 />
	  <label>Factorize numbers?</label>
		
		<label style="margin-top: 20px;">Upload file</label>
		<input type="file" name="expfile" type="file" class="textfield" id="expfile" onkeyup="chkFilename()"/><div id="filenamechk" class="hidden"></div>

		<input id="doLaunch" type="submit" value="Launch" name="Launch" class="submit" />
			
    </form>
				
				
	<?php
				
				
	if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
		echo '<div class="error">';
								
	    foreach($_SESSION['ERRMSG_ARR'] as $msg) {
			#echo '<li>',$msg,'</li>'; 
			echo $msg.'<br />';
		}
		
		echo '</div>';
		
		unset($_SESSION['ERRMSG_ARR']);																							
	}
	?>
																											</body></html>
